package com.micolor.logr.demo.service.log.persistence;

import com.alibaba.fastjson2.JSONObject;
import com.micolor.logr.demo.entity.LogStorageDataEntity;
import com.micolor.logr.demo.service.ILogStorageDataService;
import com.micolor.logr.runtime.entity.StorageData;
import com.micolor.logr.runtime.interfaces.LogDataPersistenceInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author EvanGe
 * @Type LogDataPersistenceImpl.java
 * @Desc
 * @date 2024/7/17 14:40
 */
@Component
@Slf4j
public class LogDataPersistenceImpl implements LogDataPersistenceInterface {

    @Autowired
    ILogStorageDataService logStorageDataService ;

    /**
     * 保存日志数据
     * @param storageData 日志数据
     */
    @Override
    public void invokeSaveLogData(StorageData storageData) {
        LogStorageDataEntity logStorageDataEntity = new LogStorageDataEntity(storageData);
        logStorageDataEntity.setLogId(UUID.randomUUID().toString().replaceAll("-",""));
        logStorageDataService.save(logStorageDataEntity);
        log.info("logStorageDataEntity:{}",logStorageDataEntity);
    }
}
